/*******************************************************************************
* Long-term effects of weather-induced migration on urban labor and housing 
  markets
* Busso & Chauvin

* Purpose: Create map of 

*******************************************************************************/
/*----------------------------------------------------------------------------
/* Set up */
----------------------------------------------------------------------------*/
cap mkdir "$da_out/graphs" 
global save "$da_out/graphs"
global geocodefile "$db_inp/geo_codes_sat_cities.dta"

use "${db_tmp}/drought_index_spei8010.dta", replace

preserve
use  mca8010 mcarp8010 using "${geocodefile}", clear
drop if mcarp8010 != 1000000
drop mcarp8010
duplicates drop
tempfile rural
save `rural'
restore
 
merge 1:1 mca8010 using `rural', keep(3)
drop _merge

/*----------------------------------------------------------------------------
/* Open the dataset that relates muni codes and coordinates */
----------------------------------------------------------------------------*/
merge m:1 mca8010 using "$db_inp/shapefiles/mca8010", keepusing(id)
rename _merge mapmerge

drop if mapmerge == 1

/*----------------------------------------------------------------------------
/* Map of geographic variation in dryness across rural municipalities in 
the 2000–2009 period */
----------------------------------------------------------------------------*/
format (drought_dws0009) %12.2f

spmap drought_dws0009 using "$db_inp/shapefiles/mca8010_coor", ///
id(id)  ocolor(white ..) osize(vvvthin ..) legstyle(2) legend(position(7)) ///
fcolor(Reds) polygon(data("$db_inp/shapefiles/coor_state") ///
ocolor(black) osize(vvthin) legenda(off)) clnumber(5) ndocolor() ndpattern(blank)   

/* Save map */
graph export "$save/map.png", as(png) width(2300) height(1800) replace
